class Solution {
public:
   static bool cmp(const vector<int>& a, const vector<int>& b) {
        return a[0] < b[0] || (a[0] == b[0] && a[1] > b[1]);
    }
    int numberOfWeakCharacters(vector<vector<int>>& properties) {
         sort(properties.begin(), properties.end(), cmp);
         stack<int>st;
         int ans=0;
        for(int i=properties.size()-1;i>=0;i--){
            while(!st.empty()&&properties[i][1]>st.top()){
                st.pop();
            }
            if(!st.empty()&&properties[i][1]<st.top()){
                ans++;
                continue;
            }
            st.push(properties[i][1]);
         }
         return ans;
    }
};
